//
//  ResetPasswordVC.m
//  Doctor
//
//  Created by 阳光 on 16/9/10.
//  Copyright © 2016年 阳光. All rights reserved.
//  找回密码界面

#import "ResetPasswordVC.h"
#import "ResetPdVC.h"

#import "CountryListVC.h"
#import "AreaListVC.h"
#import "HospitalListVC.h"
#import "ForgetPasswordVC.h"

#import "FirstVC.h"

@interface ResetPasswordVC ()<UITextFieldDelegate,CustomNavViewDelegate>

@property(nonatomic,strong)UIView *countryView;

@property(nonatomic,strong)UIView *hospitalAreaView;

@property(nonatomic,strong)UIView *jobHospitalView;

@property(nonatomic,strong)CustomButton *selectAreaBtn;

@property(nonatomic,strong)CustomButton *selectHospitalBtn;

@property(nonatomic,strong)CustomButton *selectCountryBtn;

@property(nonatomic,strong)Label_TextField_Next *codeView;

@property(nonatomic,strong)NSString *countryID;

@property(nonatomic,strong)NSString *areaID;

@property(nonatomic,strong)NSString *hospitalID;

@property(nonatomic,strong)NSString *hospitalIDStr;

@property(nonatomic,strong)NSString *hospitalNameStr;

@property(nonatomic,strong)NSMutableArray *hospitalArr;

@property(nonatomic,strong)NSMutableArray *hospitalIDArr;

@property(nonatomic,strong)NSMutableArray *areaIDArr;

@end



@implementation ResetPasswordVC

-(void)rightBtnEvent
{
    
}

-(void)leftBtnEvent
{
    [self dismissViewControllerAnimated:NO completion:nil];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor=WhiteColor;
    
    [self initMainView];
    
    _hospitalArr=[NSMutableArray array];
    
    // 注册通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tongzhi:) name:@"tongzhi" object:nil];
    
}

-(void)tongzhi:(NSNotification *)text
{

    _hospitalNameStr=text.userInfo[@"hospitalName"];
    
    _hospitalIDStr=text.userInfo[@"hospitalID"];
    
    [_selectHospitalBtn setTitle:_hospitalNameStr forState:0];
    
    NSLog(@"0022--%@ 888%@",_hospitalIDStr,_hospitalNameStr);
    
}

-(void)selectHospitalBtnEvent1
{
    NSLog(@"走哪了去了。。。");
    
//    FirstVC *countryListVC=[FirstVC new];
//    [self presentViewController:countryListVC animated:NO completion:nil];
    
    // 跳转到国家列表界面
    CountryListVC *countryListVC=[CountryListVC new];
    [self presentViewController:countryListVC animated:NO completion:nil];

    
}

-(void)initMainView
{
    CustomNavView *registerNavView=[[CustomNavView alloc]initWithTitle:NSLocalizedString(@"Forgot password", nil) leftBtnImage:@"back_gray" hasLeftBtnImage:YES rightBtnTitle:nil hasRightBtnTitle:NO];//@"Find Password";@"找回密码"
    registerNavView.delegate=self;
    registerNavView.frame=CGRectMake(0,0,APPW,64);
    [self.view addSubview:registerNavView];
    
    // 就职医院
    {
        _jobHospitalView=[UIView new];
        [self.view addSubview:_jobHospitalView];
        _jobHospitalView.backgroundColor=WhiteColor;
        [_jobHospitalView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(APPW,kmargin*5));
            make.top.mas_equalTo(64);
            make.left.right.mas_equalTo(0);
        }];
        
        UILabel *jobHospitalLabel=[_jobHospitalView getLabelWithText:NSLocalizedString(@"Clinic", nil) font:Font_Number(16) textColor:Color666666 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];//@"就职医院"
        [_jobHospitalView addSubview:jobHospitalLabel];
        [jobHospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(kmargin);
            make.bottom.mas_equalTo(-kmargin);
        }];
        
        // 选择医院
        _selectHospitalBtn=[CustomButton buttonWithType:UIButtonTypeCustom];
        _selectHospitalBtn.titleLabel.font=Font_Number(16);
        [_selectHospitalBtn setTitleColor:ColorBDBDBD forState:0];
        [_selectHospitalBtn setTitle:NSLocalizedString(@"Select Hospital", nil) forState:0];
        [_selectHospitalBtn setImage:[UIImage imageNamed:@"cell_arrow"] forState:0];
        _selectHospitalBtn.status = FLAlignmentStatusCenter;
        [_selectHospitalBtn addTarget:self action:@selector(selectHospitalBtnEvent1) forControlEvents:UIControlEventTouchUpInside];
        [_jobHospitalView addSubview:_selectHospitalBtn];
        [_selectHospitalBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin);
            make.centerY.mas_equalTo(jobHospitalLabel.mas_centerY);
        }];
        
        UIView *jobHospitalLine=[UIView new];
        [_jobHospitalView addSubview:jobHospitalLine];
        jobHospitalLine.backgroundColor=MAIN_BACK_COLOR;
        [jobHospitalLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(APPW,1));
            make.bottom.mas_equalTo(0);
        }];
    }
    
    // 执照号
    {
        _codeView=[[Label_TextField_Next alloc]initWithTitle:NSLocalizedString(@"License No.", nil) placeholder:NSLocalizedString(@"Enter license no.", nil)];//请输入执照号;
        _codeView.textField.keyboardType=UIKeyboardTypeNumberPad;
        _codeView.textField.delegate=self;
        _codeView.textField.textAlignment=NSTextAlignmentRight;
        _codeView.backgroundColor=WhiteColor;
        [self.view addSubview:_codeView];
        [_codeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.jobHospitalView.mas_bottom);
            make.size.mas_equalTo(CGSizeMake(APPW,kmargin*5));
        }];
        UIView *codeViewLine=[UIView new];
        [_codeView addSubview:codeViewLine];
        codeViewLine.backgroundColor=MAIN_BACK_COLOR;
        [codeViewLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(APPW,1));
            make.bottom.mas_equalTo(0);
        }];
    }
    
    // 下一步
    {
        UIButton *nextBtn=[UIButton new];
        [self.view addSubview:nextBtn];
        nextBtn.backgroundColor=Main_Color;
        nextBtn.titleLabel.font=Font_Number(16);
        ViewBorderRadius(nextBtn,kmargin/2,1,ClearColor);
        [nextBtn setTitle:NSLocalizedString(@"Next Step", nil) forState:UIControlStateNormal];//@"下一步"
        [nextBtn setTitleColor:WhiteColor forState:UIControlStateNormal];
        [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.codeView.mas_bottom).offset(kmargin*2);
            make.size.mas_equalTo(CGSizeMake(APPW-kmargin*6,40));
            make.left.mas_equalTo(kmargin*3);
        }];
        [nextBtn addTarget:self action:@selector(nextBtnEvent) forControlEvents:UIControlEventTouchUpInside];
    }
    
}

-(void)nextBtnEvent
{
    NSDictionary *dic=@{
                        @"shop_id":_hospitalIDStr,
                        @"document_number":_codeView.textField.text
                        };
    
    [QBRequest ForgetUserNameOrPasswordWithDic:dic Success:^(id res)
    {
        //NSLog(@"9999-0-#%@",res);
        if ([res[@"message"] isEqualToString:@"用户信息获取成功"]) {//.
            [self.view makeToast:NSLocalizedString(@"Got user info succeed", nil) duration:1.0 position:CSToastPositionCenter];
        } else {
           [self.view makeToast:res[@"message"] duration:1.0 position:CSToastPositionCenter];
        }
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(1.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
        // 跳转忘记密码重置密码界面
        ForgetPasswordVC *forgetPasswordVC=[ForgetPasswordVC new];
        forgetPasswordVC.infoDic=res[@"info"];
        [self presentViewController:forgetPasswordVC animated:NO completion:nil];
//        [self.navigationController pushViewController:forgetPasswordVC animated:NO];
            
        });
        
    } failure:^(NSString *error)
    {
        
    }];
}

-(void)initNavBarBtnItem
{
    self.navigationItem.leftBarButtonItem=[UIBarButtonItem initWithNormalImage:@"back_gray" target:self action:@selector(backItemEvent)];
}

-(void)backItemEvent
{
    [self.navigationController popViewControllerAnimated:NO];
}

@end
